package com.hui.quartz;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


/***
 * spring自带的定时器
 */
@Component
public class SpringScheduledDemo {

//    @Scheduled(cron = "0 0/1 * * * ?") // 每分钟执行一次
//    public void work() throws Exception {
//        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++");
//        System.out.println(this.getClass().hashCode());
//        System.out.println(Thread.currentThread().getName());
//        System.out.println("执行调度任务：" + new Date());
//    }

//
//    @Scheduled(fixedRate = 5000)//每5秒执行一次
//    public void play() throws Exception {
//        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++");
//        System.out.println("当前类:" + this.getClass().getName());
//        System.out.println("当前线程" + Thread.currentThread().getName());
//        System.out.println("每5秒执行一次：" + LocalDateTime.now().plusDays(1).format(DateTimeFormatter.ofPattern("yyy-MM-dd HH:mm:ss")));
//    }


//    @Scheduled(cron = "0/2 * * * * ?") //每2秒执行一次
//    public void doSomething() throws Exception {
//        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++");
//        System.out.println(this.getClass().hashCode());
//        System.out.println(Thread.currentThread().getName());
//        System.out.println("每2秒执行一个的定时任务：" + new Date());
//    }


//    @Scheduled(cron = "0 0 0/1 * * ? ") // 每一小时执行一次
//    public void goWork() throws Exception {
//        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++");
//        System.out.println(this.getClass().hashCode());
//        System.out.println(Thread.currentThread().getName());
//        System.out.println("每一小时执行一次的定时任务：" + new Date());
//    }


}